package com.ruimei;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import com.ruimei.interceptor.LoginHandlerInterceptor;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private LoginHandlerInterceptor loginInterceptor;

    /**
     * 重写添加拦截器方法并添加配置拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")   //拦截哪些路径("/**":代表拦截所有路径);
                .excludePathPatterns
                        ("/login", "/logout","/error","/getCode","/parent/getcode","/getRegisterCode/*","/parentRegister",
                                "/teacher/getpassword","/parent/getpassword","/*.html",//不拦截哪些路径;
                                "/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**");  //swagger不拦截
    }
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) { //swagger不拦截方法
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
